<?php
/**
 * User: @huining
 * Date: 2019-11-20
 * Time: 16:59
 */

namespace Frieza\Modules\Photo\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Illuminate\Http\Request;
use Doraemon\service\PhotoAudit\Schedule;
use Encore\Admin\Widgets\Tab;
use Encore\Admin\Grid;
use App\Pockets\GridDataModel as pGridDataModel;


class PhotoAuditController extends Controller
{
    const PAGE_SIZE = 20;

    public function __construct()
    {
       Admin::script('$(".pjax-container").attr("id","pjax-container");');
    }

    public function index(Request $request, Content $content)
    {
        $params = $request->all();
        dump($params);
        Schedule::getList();

        $tab = new Tab();
        //资源位
        //$id = $request->input('id'); // 增加筛选项

     //   $list = AdmOperationModule::getPositionMap();

        foreach (Schedule::AUDIT_TAB_MAP as $audit_tab_id => $name) {
            $audit_list = $list[$audit_tab_id] ?? [];
            $gridModel = new pGridDataModel($audit_list);
            $gridMap = Admin::grid($gridModel,
                function (Grid $grid) {
                    //  $grid->disableFilter();
                    $grid->filter(function (Grid\Filter $filter) {
                        $filter->disableIdFilter();
                        $filter->column(1/2 ,function ($filter){
                             $filter->equal("violation_type" ,'违规类型') ->radio([
                                  0 => "全部",
                                  1 => "违规",
                                  2=>"疑似违规"
                             ]) ->default(0);
                             $filter->equal("check_status" , "审核状态") ->radio([
                                  1 => "未审核" ,
                                  2 => "已审核"
                             ]);
                        });
                        $filter->column(1/2 ,function ($filter){
                            $filter->between("add_time" ,'发图时间') ->datetime();
                            $filter->equal("uid" )->placeholder('请输入用户uid');
                        });
                    });
                    $grid->disableExport();
                    $grid->disableCreateButton();
                    $grid->disableRowSelector();
                    // $grid->disablePagination();
                    $grid->column('id', '资源位ID')->sort();
                    $grid->column('title', '资源位置名称');
                    $grid->column('version', '支持版本') ->display(function ($version){
                        return str_replace(".",'_',$version);
                    });
                    $grid->column('drop_version', '废弃版本');
                    $grid->actions(function (Grid\Displayers\Actions $actions) {
//                        $actions->append('<a href="'. $actions->row->route .'" ><i class="fa fa-info-circle">查看</i></a>');
                    });
                });
            $tab->add($name, $gridMap->render());
        }




        return $content
            ->header('图片审核')
            ->description(' ')
            ->breadcrumb(['text' => '图片审核'])
            ->row($tab);
        dump($params);



    }






}